package rsj.api.product;

import com.rlyy.aibase.utils.base.Box;
import com.rlyy.aibase.utils.base.MapNode;
import com.rlyy.aibase.utils.base.TableNode;
import common.util.Assert;
import common.util.BoxUtil;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import rsj.api.user.BaseLink;
import rsj.domain.ProdUpListQuery;
import rsj.service.ProdUpService;
@RestController
public class GetDocUpList extends BaseLink {

    private static final ProdUpService prodUpService = ProdUpService.getInstance();

    @RequestMapping(value = "rsj_prod_updateList")
    public Box executeLink(Box in){
        MapNode data = in.getMapNode("data");

        ProdUpListQuery query = buildPageQuery(data);

        TableNode tableNodes = prodUpService.getUpPro(query);
        int totalPageSize = prodUpService.getUpProTotalSize(query);

        MapNode outData = new MapNode();
        outData.putNode("ProUp_List", tableNodes.toJson());
        outData.putNode("ProUp_Count", String.valueOf(totalPageSize));

        return BoxUtil.successBoxToData(in, "获取用户查询列表信息！", outData);
    }

    private ProdUpListQuery buildPageQuery(MapNode data) {
        ProdUpListQuery query = new ProdUpListQuery();

        Assert.notNull(data, "传入数据不能为空！");
        Assert.isNotBlank(data.getValue("Prod_Id"), "Prod_Id参数不能为空！");

        query.setProd_Id(data.getValue("Prod_Id"));
        query.setPageCount(data.getValueIntDef("Page_Count", 0));
        query.setPageSize(data.getValueIntDef("Page_Size", 0));
        return query;
    }

}
